#coding=utf-8
import uuid
from flask import Flask, current_app
from flaskext.script import Server, Shell, Manager, Command, prompt_bool

from ext.model import engine, DBSession
from apps import create_app

app = create_app('../config.py')
manager = Manager(app)
manager.add_command("runserver", Server(app.config['HOST'], port=app.config['PORT']))
manager.add_command("shell", Shell(make_context=lambda: dict(app=app, DBSession=DBSession)))

@manager.command
def createall():
    for i in app.config['APP_MODULES']:
        _mod = __import__('apps.%s.models' % i, fromlist=['*'])
        print 'create tables for mod: %s' % _mod
    engine.create_all()

@manager.command
def dropall():
    if prompt_bool("Are you sure ? You will lose all your data !"):
        engine.drop_all()

if __name__ == "__main__":
    manager.run()
